//
//  CRCommentCell.m
//  CRChatRoom
//
//  Created by CuiFengshuai on 15/11/28.
//  Copyright © 2015年 SecondGroup. All rights reserved.
//

#import "CRCommentCell.h"
#import "CRComment.h"
#import "UIImageView+WebCache.h"
#import "UIImageView+CRExtension.h"
#import "CRUser_MK.h"
@interface CRCommentCell ()


@property (weak, nonatomic) IBOutlet UIImageView *profileImageView;
@property (weak, nonatomic) IBOutlet UIImageView *sexView;
@property (weak, nonatomic) IBOutlet UILabel *contentLabel;
@property (weak, nonatomic) IBOutlet UILabel *usernameLabel;
@property (weak, nonatomic) IBOutlet UILabel *likeCountLabel;
@property (weak, nonatomic) IBOutlet UIButton *voiceButton;

@end

@implementation CRCommentCell

- (void)awakeFromNib {
    UIImageView *bgView = [[UIImageView alloc] init];
    bgView.image = [UIImage imageNamed:@"mainCellBackground"];
    self.backgroundView = bgView;
}

- (void)setComment:(CRComment *)comment {
    if (_comment != comment) {
        _comment = nil;
        _comment = comment;
        [self setupSubviews];
    }
}

- (void)setupSubviews {
    [self.profileImageView setHeaderWithUrl:self.comment.user.profile_image];
    self.sexView.image = [self.comment.user.sex isEqualToString:CRUserSexMale] ? [UIImage imageNamed:@"Profile_manIcon"] : [UIImage imageNamed:@"Profile_womanIcon"];
    self.contentLabel.text = self.comment.content;
    self.usernameLabel.text = self.comment.user.username;
    self.likeCountLabel.text = [NSString stringWithFormat:@"%zd", self.comment.like_count];
    
    if (self.comment.voiceuri.length) {
        self.voiceButton.hidden = NO;
        [self.voiceButton setTitle:[NSString stringWithFormat:@"%zd''", self.comment.voicetime] forState:UIControlStateNormal];
    } else {
        self.voiceButton.hidden = YES;
    }
    
    
}

@end
